package com.baigt.jvm.gc;

import java.util.concurrent.TimeUnit;

/**
 * 使用jconsole工具查看
 * 连接后选择线程tab查看
 */
public class GCDeadLockDemo {
    public static void main(String[] args) {
        new Thread(One::doSomeThing,"Thread-A").start();
        new Thread(Two::doSomeThing,"Thread-B").start();
    }
}

class One {
    public synchronized static void doSomeThing(){
        try {
            TimeUnit.SECONDS.sleep(2);
            Two.doSomeThing();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
class Two {
    public static synchronized void doSomeThing(){
        try {
            TimeUnit.SECONDS.sleep(2);
            One.doSomeThing();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}